Skip to content

Add integration tests for SSH Command using pytest-homeassistant-custom-component#8

Merged
gensyn merged 3 commits intomainfrom
copilot/add-integration-tests-for-component
Mar 22, 2026
Merged

Add integration tests for SSH Command using pytest-homeassistant-custom-component#8
gensyn merged 3 commits intomainfrom
copilot/add-integration-tests-for-component

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

Adds real Home Assistant integration tests (using pytest-homeassistant-custom-component) mirroring the pattern from task_tracker PR #21, and relocates unit tests from test/ to tests/unit_tests/.

Test structure

  • tests/unit_tests/ — existing unit tests (moved from test/; path depth updated from parent×3parent×4)
  • tests/integration_tests/conftest.py — creates custom_components/ssh_command → <repo_root> symlink at test collection time so HA's loader discovers the component; provides auto_enable_custom_integrations fixture
  • tests/integration_tests/test_integration.py — 29 tests against a live in-process HomeAssistant instance, with only asyncssh patched out

Integration test coverage

Class What's tested
TestSetupEntry Coordinator in hass.data, service registered, single-instance guard
TestUnloadEntry Coordinator removed on unload
TestConfigFlow Entry created, second attempt aborted
TestExecuteServiceSuccess stdout/stderr/exit_status, password & key-file auth, inline & file input, custom timeout
TestExecuteServiceKnownHosts check_known_hosts=FalseNone, custom/missing file, default ~/.ssh/known_hosts
TestExecuteServiceValidation All 5 _validate_service_data error paths, including no coordinator present
TestExecuteServiceErrors All SSH exception types (HostKeyNotVerifiable, PermissionDenied, TimeoutError, gaierror, generic OSError)

Infra changes

  • requirements_integration_tests.txtpytest-homeassistant-custom-component==0.13.318
  • pytest.iniasyncio_mode = auto
  • .github/workflows/integration-tests.yml — new CI job running pytest tests/integration_tests/ -v
  • test.yml updated to discover -s tests/unit_tests
  • pylint.yml ignore-paths updated to ^tests/.*$
  • run_tests.sh updated to tests/unit_tests
  • .gitignore excludes custom_components/ (created at runtime by conftest.py)

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Co-authored-by: gensyn <36128035+gensyn@users.noreply.github.com>
Copilot AI changed the title [WIP] Add integration tests for Task Tracker component Add integration tests for SSH Command using pytest-homeassistant-custom-component Mar 17, 2026
Copilot AI requested a review from gensyn March 17, 2026 17:09
@gensyn
Copy link
Owner

gensyn commented Mar 22, 2026

@copilot The GitHub workflow for integration tests fails with
"""

Run pytest tests/integration_tests/ -v
pytest tests/integration_tests/ -v
shell: /usr/bin/bash -e {0}
env:
pythonLocation: /opt/hostedtoolcache/Python/3.14.3/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.14.3/x64/lib
ImportError while loading conftest '/home/runner/work/ssh_command/ssh_command/tests/integration_tests/conftest.py'.
init.py:8: in
from aiofiles.ospath import exists
E ModuleNotFoundError: No module named 'aiofiles'
Error: Process completed with exit code 4.
"""

Copy link
Contributor Author

Copilot AI commented Mar 22, 2026

@copilot The GitHub workflow for integration tests fails with
"""

...

The CI was failing because the integration-tests workflow only installed requirements_integration_tests.txt but not the component's own dependencies (aiofiles, asyncssh). When pytest loaded conftest.py, it triggered the import of __init__.py which imports from aiofiles.ospath import exists — hence the ModuleNotFoundError.

Fixed in b472b92 by adding pip install -r requirements.txt before the integration test requirements in the workflow.

@gensyn gensyn marked this pull request as ready for review March 22, 2026 19:20
@gensyn gensyn merged commit 5321b6d into main Mar 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants